package com.neusoft.elmboot.service.Impl;

import com.neusoft.elmboot.mapper.EnvelopeMapper;
import com.neusoft.elmboot.mapper.UserMapper;
import com.neusoft.elmboot.po.Envelope;
import com.neusoft.elmboot.service.EnvelopeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.neusoft.elmboot.po.User;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

/**
 * 红包实现
 * Service
 */
@Slf4j
@Service
public class EnvelopeServiceImpl implements EnvelopeService {

    Random r = new Random();

    @Autowired
    UserMapper userMapper;

    @Autowired
    EnvelopeMapper envelopeMapper;

    @Override
    public void getEnvelopeByUserId(User user) {
        Double d2 = 0.0d;
        d2 = (r.nextDouble() * 7 ) + 2; // 生成[2,9.0]区间的小数
        userMapper.updateEnvelope(user.getUserId());
        log.info("调用方法：生成红包");
        envelopeMapper.getEnvelopeByUserId(user.getUserId(),d2);
    }

    @Override
    public List<Envelope> listEnvelopeByUserId(String userId) {
        List<Envelope>list = envelopeMapper.listEnvelopeByUserId(userId);
        return list;
    }

    @Override
    public Double getEnvelopeAmountById(Integer id) {

        return envelopeMapper.getEnvelopeAmountById(id);
    }


}
